<template>
  <div>
    <!-- header -->
    <van-nav-bar
      :title="title"
      left-text="返回"
      left-arrow
      fixed
      @click-left="onClickLeft"
    >

    </van-nav-bar>
    <!-- 中间切换 的页面 -->
    <router-view></router-view>
    <!-- footer -->
    <van-tabbar v-model="active">
      <van-tabbar-item
        icon="home-o"
        to="/home"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="friends-o"
        to="/friends"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="cart-o"
        badge="6"
        to="/cart"
      ></van-tabbar-item>
      <van-tabbar-item
        icon="search"
        to="/search"
      ></van-tabbar-item>
    </van-tabbar>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 防止刷新的时候title丢失
      title: this.$route.meta.title || '首页',
      active: 0
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1)
    }
  },
  watch: {
    // 监听路由的变化动态修改title
    $route(newVal) {
      this.title = newVal.meta.title
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
